const employmentModel = require("../model/employmentModel")
// const studentModel = require("../model/studentModel")
// const companyModel = require("../model/companyModel")

module.exports = {
    addList(data) {
        // console.log(data)
        // return employmentModel.create(data)
        return Promise.all(data.map(obj => {
            return employmentModel.findOneAndUpdate({
                company: obj.company,
                studentname: obj.studentname
            }, {
                $set: obj
            }, {
                upsert: true
            }).exec()
        }))
    },
    getList() {
        return employmentModel.find()
    },
    update(id, { key, value }) {
        return employmentModel.findOneAndUpdate({ _id: id }, {
            $set: {
                ["score." + key]:  value
            }
        })
    },
    delete(data) {
        console.log(data.id)
        return employmentModel.findOneAndDelete({ _id: data.id })
    }
}